﻿@model PromoCodes_GUI.Models.ListViewModel<PromoCodes_Models.Entities.Promotion>

@{
    ViewBag.Title = "Index";
}

<h2>Promotions</h2>
@Html.ActionLink("New...", "AddPromotion", "Promotion")
<div>
<div class="pager" id="top">
@Html.PageLinks(Model.Info, x => Url.Action("Index", new { page = x }))
</div>
<div class="Header">
    <div id="promo_name_h">Promotion</div><div id="promo_exp_h">Expiration Date</div><div id="promo_opt_h">Options</div>
</div>
@if(Model.Info.TotalItems > 0)
{
foreach (var promotion in Model.PageItems)
{
    string promotionInfo = "";
    if (promotion.DiscountType == PromoCodes_Models.Entities.DiscountType.ORDER)
    {
        promotionInfo = ((promotion.MinimumTotalOrder > 0) ? "$" + promotion.MinimumTotalOrder : "TOTAL") + " ORDER ";
    }
    else
    {
        promotionInfo = promotion.Product.ProductName;
    }
    <div class="Promotion">
        <div class="Link">@Html.ActionLink(promotion.PromotionCode + " " + promotion.DiscountPercentage + "% OFF " + promotionInfo, "AddPromotion", "Promotion", new { ID = promotion.PromotionID }, null)</div>
        @if (promotion.Expiration.CompareTo(DateTime.Now) > 0)
        {
            <div class="Running">@promotion.Expiration</div>
        }
        else
        {
            <div class="Expired">@promotion.Expiration</div>
        }
        <div class="Options">
            @using (@Html.BeginForm("AddPromotion", "Promotion", FormMethod.Get))
            {
                @Html.Hidden("id", promotion.PromotionID)
                <input type="submit" value="Edit" />
            }
            @using (@Html.BeginForm("Delete", "Promotion"))
            {
                @Html.Hidden("id", promotion.PromotionID)
                <input type="submit" value="Delete" />
            }
        </div>
    </div>
}
}
else
{
    <div class="Promotion" id="empty">
     There are currently no promotions running...
    </div>
}
<div class="pager" id="bottom">
@Html.PageLinks(Model.Info, x => Url.Action("Index", new { page = x}))
</div>
</div>